﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>供应商管理</title>
    <link rel="stylesheet" href="../../../assets/libs/layui/css/layui.css"/>
    <link rel="stylesheet" href="../../../assets/module/admin.css?v=317"/>
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<!-- 页面加载loading -->
<div class="page-loading">
    <div class="ball-loader">
        <span></span><span></span><span></span><span></span>
    </div>
</div>
<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 表格工具栏 -->
            <form class="layui-form toolbar">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">查询条件:</label>
                        <div class="layui-input-inline">
                            <input name="search" class="layui-input" placeholder="请输入"/>
                        </div>
                    </div>
                    <div class="layui-inline">&emsp;
                        <button class="layui-btn icon-btn" lay-filter="searchBtn" lay-submit>
                            <i class="layui-icon">&#xe615;</i>搜索
                        </button>
                    </div>
                </div>
            </form>
            <!-- 数据表格 -->
            <table id="tableField" lay-filter="tableField"></table>
        </div>
    </div>
</div>
<script type="text/html" id="supplierDialog">
    <form id="createForm" lay-filter="createForm" class="layui-form model-form"
          style="padding-right: 20px;">
        <input hidden name="accountId">
        <div class="layui-row">
            <div>
                <div class="layui-form-item">
                    <label class="layui-form-label layui-form-required">合作商类型</label>
                    <div class="layui-input-block">
                        <select name="supplierType" lay-verify="required">
                            <option value="1">供应商</option>
                            <option value="2">客户</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label layui-form-required">合作商</label>
                    <div class="layui-input-block">
                        <input name="supplierName" placeholder="请输入" class="layui-input"
                               lay-verify="required"/>
                    </div>
                </div>
                <div class="layui-form-item"><label class="layui-form-label layui-form-required">统一信用社代码:</label>
                    <div class="layui-input-block"><input name="regCode" placeholder="请输入权限标识" class="layui-input"
                                                          lay-verify="required"/></div>
                </div>
                <div class="layui-form-item"><label class="layui-form-label layui-form-required">法人:</label>
                    <div class="layui-input-block"><input name="legalPerson" placeholder="请输入" class="layui-input"
                                                          lay-verify="required"/>
                    </div>
                </div>
                <div class="layui-form-item"><label class="layui-form-label layui-form-required">法人证件号:</label>
                    <div class="layui-input-block"><input name="legalPersonIdentity" placeholder="请输入"
                                                          class="layui-input" lay-verify="required"/></div>
                </div>
                <div class="layui-form-item"><label class="layui-form-label layui-form-required">法人证件类型:</label>
                    <div class="layui-input-block">
                        <select name="legalPersonIdentityType" lay-verify="required">
                            <option value="0">身份证</option>
                            <option value="1">护照</option>
                            <option value="B">港澳居民往来内地通行证</option>
                            <option value="C">台湾居民来往大陆通行证</option>
                            <option value="E">户口簿</option>
                            <option value="F">临时居民身份证</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item"><label
                        class="layui-form-label layui-form-required">法人联系方式:</label>
                    <div class="layui-input-block"><input name="contactMobile" placeholder="请输入"
                                                          class="layui-input" lay-verify="required"/></div>
                </div>
            </div>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn" lay-filter="addBtn" lay-submit>保存</button>
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
        </div>
    </form>

</script>
<script type="text/html" id="contractDialog">
    <form id="contractForm" lay-filter="contractForm" class="layui-form model-form"
          style="padding-right: 20px;">
        <input hidden name="supId">
        <div class="layui-row">
            <div class="layui-form-item">
                <label class="layui-form-label layui-form-required">上传合同</label>
                <div class="layui-input-block">
                    <button type="button" class="layui-btn layui-btn-normal" id="upload"> <i class="layui-icon">&#xe67c;</i>选择合同</button>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label layui-form-required">合同标题</label>
                <div class="layui-input-block">
                    <input name="title" class="layui-input" autocomplete="off">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label layui-form-required">合同有效期</label>
                <div class="layui-input-block">
                    <input name="expireTime" class="layui-input" id="expireTime" autocomplete="off">
                </div>
            </div>
        </div>
        <div class="layui-form-item text-right">
            <a class="layui-btn" id="action" lay-submit>保存</a>
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
        </div>
    </form>
</script>
<!-- 表格操作列 -->
<script type="text/html" id="thBar">
    <a class="layui-btn layui-btn-xs" lay-event="change">生成账号</a>
</script>
<!-- js部分 -->
<script type="text/javascript" src="../../../assets/libs/layui/layui.js"></script>
<script type="text/javascript" src="../../../assets/js/common.js?v=317"></script>
<script type="text/javascript" src="../../../assets/js/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="../../../assets/js/js.cookie.min.js"></script>
<script type="text/javascript" src="../../../assets/js/sqjx.js"></script>
<script>
    layui.use(['layer', 'form', 'table', 'upload','laydate','dropdown'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        /* 渲染表格 */
        var insTb = table.render({
            elem: '#tableField',
            url: '/contract/supplier/queryAllSupplier',
            page:true,
            method: 'post',
            request: {
                pageName: 'page',
                limitName: 'rows',
            },
            cellMinWidth: 100,
            height: $(window).height() - 100,
            cols: [[
                {type: 'numbers'},
                {field: 'label', title: '企业',},
                {
                    field: 'crmType', title: '合作商类型', templet(row) {
                        return row.crmType == 1 ? '供应商' : '客户';
                    }
                },
            ]],
            parseData: function (res) {
                res = res.obj;
                return {
                    "code": 0,
                    "msg": "",
                    "count": res.total,
                    "data": res
                }
            }
        });

        /* 表格搜索 */
        form.on('submit(searchBtn)', function (data) {
            insTb.reload({where: data.field, page: {curr: 1}});
            return false;
        });

        /* 表格工具条点击事件 */
        table.on('tool(tableField)', function (obj) {
            var data = obj.data;
            if (obj.event === 'change') { // 下载文件
                handleCreateAccount(data)
            }
        });

        /* 表格头工具栏点击事件 */
        table.on('toolbar(tableField)', function (obj) {
            if (obj.event === 'add') { // 打开上传文件窗口
                openHandleSupplier(obj.data);
            }
        });

        function handleCreateAccount(data) {
            layer.confirm('确认生成企业账号？', function () {
                $.post('/contract/supplier/createSysAccount', data, function (res) {
                    if (res.code == 200) {
                        insTb.reload({where: data.field, page: {curr: 1}});
                        closeDialog();
                        showAlert(res.msg, 1);
                    } else {
                        showAlert(res.msg);
                    }
                })
            })
        }

        /* 显示表单弹窗 */
        function openHandleSupplier() {
            layer.open({
                type: 1,
                offset: 't',
                area: ['60%', '100%'],
                content: $('#supplierDialog').html(),
                success: function (layero, dIndex) {
                    form.render();
                    form.on('submit(addBtn)', function (obj) {
                        $.post('/contract/supplier/addSupplier', obj.field, function (res) {
                            if (res.code == 200) {
                                insTb.reload({page: {curr: 1}});

                                closeDialog();
                                showAlert(res.msg, 1);
                            } else {
                                showAlert(res.msg);
                            }
                        });
                        return false;
                    })
                }
            });
        }
    });
</script>
</body>
</html>
